<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<%@ include file="/WEB-INF/views/include/easyui.jsp"%>
<script src="${ctx}/static/plugins/My97DatePicker/WdatePicker.js" type="text/javascript"></script>

</head>
<body style="font-family: '微软雅黑'">
	<div id="tb" style="padding: 5px; height: auto">
		<div>
			<form id="searchFrom" action="">
				<input type="text" name="filter_LIKES_title"
					class="easyui-validatebox" data-options="width:180,prompt: '新闻标题'" />
				<select id="cc" class="easyui-combobox" name="filter_LIKES_conttype"
					data-options="width:180,panelHeight:100,prompt: '新闻类型'" readonly>
					<option value="">--全部--</option>
					<option value="1">产品咨询</option>
					<option value="2">金融知识</option>
					<option value="3">行业研究</option>
				</select> <span class="toolbar-item dialog-tool-separator"></span> <a
					href="javascript(0)" class="easyui-linkbutton" plain="true"
					iconCls="icon-search" onclick="cx()">查询</a>
			</form>
			<!--  -->
			<shiro:hasPermission name="lcs:knowledge:add">
				<a href="#" class="easyui-linkbutton" plain="true"
					iconCls="icon-add" onclick="add();">添加</a>
				<span class="toolbar-item dialog-tool-separator"></span>
			</shiro:hasPermission>
			<shiro:hasPermission name="lcs:knowledge:delete">
				<a href="#" class="easyui-linkbutton" plain="true"
					iconCls="icon-remove" onclick="del()">删除</a>
				<span class="toolbar-item dialog-tool-separator"></span>
			</shiro:hasPermission>
			<shiro:hasPermission name="lcs:knowledge:update">
				<a href="#" class="easyui-linkbutton" plain="true"
					iconCls="icon-edit" onclick="upd()">修改</a>
				<span class="toolbar-item dialog-tool-separator"></span>
			</shiro:hasPermission>
			
			<shiro:hasPermission name="lcs:knowledge:upload">
				<a href="#" class="easyui-linkbutton" plain="true"
					iconCls="icon-hamburg-up" onclick="uploadImg()">图片</a>
				<span class="toolbar-item dialog-tool-separator"></span>
			</shiro:hasPermission>
			
			<shiro:hasPermission name="lcs:knowledge:edit">
				<a href="#" class="easyui-linkbutton" plain="true"
					iconCls="icon-hamburg-library" onclick="editor()">编辑</a>
				<span class="toolbar-item dialog-tool-separator"></span>
			</shiro:hasPermission>
			
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-hamburg-credit-card" plain="true" onclick="detail();">预览</a>
	       	
			<shiro:hasPermission name="lcs:knowledge:publish">
				<span class="toolbar-item dialog-tool-separator"></span>
				<a href="#" class="easyui-linkbutton" plain="true"
					iconCls="icon-hamburg-product" onclick="publish()">发布</a>
			</shiro:hasPermission>
			
		</div>
	</div>
	<table id="dg"></table>

	<div id="dlg"></div>
	<div id="icon_dlg"></div>
	<div id="editor_dlg"></div>
	<script type="text/javascript">
		var dg;
		var d;
		var permissionDg;
		var parentPermId;
		$(function() {
			dg = $('#dg').datagrid({
				method : "get",
				url : '${ctx}/knowledge/klg/json',
				fit : true,
				fitColumns : true,
				border : false,
				idField : 'id',
				striped : true,
				pagination : true,
				rownumbers : true,
				pageNumber : 1,
				pageSize : 20,
				pageList : [ 10, 20, 30, 40, 50 ],
				singleSelect : true,
				columns : [ [ {
					field : 'id',
					title : 'id',
					hidden : true,
					width : 100
				}, {
					field : 'imgurl',
					title : '新闻图片',
					align:'center',
					sortable:false,
					formatter:function(value,rowData,rowIndex){
						var tem='<img width="75" height="60" src="'+value+'" />';
						if(value==null||value=='')
							tem='';
						return tem;},
					width : 50
				}, {
					field : 'title',
					title : '新闻标题',
					sortable:false,
					width : 140
				}, {
					field : 'content',
					title : '新闻内容',
					sortable:false,
					width : 50,
					hidden : true
				}, {
					field : 'conttype',
					title : '新闻类型',
					align:'center',
					sortable:false,
					formatter : function(value, row, index) {
						if (value == 1) {
							return "产品咨询";
						} else if (value == 2) {
							return "金融知识";
						} else if (value == 3) {
							return "行业研究";
						} else
							return "未知";
					},
					width : 40
				}, {
					field : 'filetype',
					title : '文件类型',
					sortable:false,
					formatter : function(value, row, index) {
						if (value == '' || value == null)
							return "未知";
					},
					width : 100,
					hidden : true
				}, {
					field : 'source',
					title : '新闻来源',
					sortable:false,
					align:'center',
					width : 50
				}, {
					field : 'hotlevel',
					title : '新闻热度',
					sortable:false,
					align:'center',
					formatter : function(value, row, index) {
						if(value == '3') {
							return "<span style='color: red;'>轮播</span>";
						} else if(value == '2') {
							return "<span style='color: green;'>热门</span>";
						} else if(value == '1') {
							return "<span style='color: green;'>推荐</span>";
						} else {
							return "<span>普通</span>";
						}
					},
					width : 40
				}, 
				/*
				{
					field : 'url',
					title : '新闻链接',
					sortable:false,
					align:'center',
					width : 120
				},
				*/
				{field:'publishStatus',
					title:'发布状态',
					sortable:false,
					width:40,
					align:'center',
					sortable:false,
					formatter:function(value,rowData,rowIndex){
						if(value == '0') {
							return "<span style='color: red;'>未发布</span>";
						} else {
							return "<span style='color: green;'>已发布</span>";
						}
					}
				}, {
					field : 'publishTime',
					title : '发布时间',
					sortable:false,
					align:'center',
					formatter : function(value, row, index) {
						return formatTime(value);
					},
					width : 68
				} ] ],
				enableHeaderClickMenu: false,
			    enableHeaderContextMenu: false,
			    enableRowContextMenu: false,
				toolbar : '#tb'
			});

		});

		//弹窗增加
		function add() {
			//父级权限
			var row = dg.datagrid('getSelected');
			if (row) {
				parentPermId = row.id;
			}

			d = $('#dlg').dialog({
				title : '添加新闻',
				width : 450,
				height : 200,
				closed : false,
				cache : false,
				maximizable : true,
				resizable : true,
				href : '${ctx}/knowledge/create',
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						$("#mainform").submit();
						dg.datagrid('reload');
					}
				}, {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});
		}

		//删除
		function del() {
			var row = dg.datagrid('getSelected');
			if (rowIsNull(row))
				return;
			parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function(data) {
				if (data) {
					$.ajax({
						type : 'get',
						url : "${ctx}/knowledge/delete/" + row.id,
						success : function(data) {
							if (successTip(data, dg))
								dg.datagrid('reload');
						}
					});
					//dg.datagrid('reload'); //grid移除一行,不需要再刷新
				}
			});

		}
		//修改
		function upd() {
			var row = dg.datagrid('getSelected');
			if (rowIsNull(row))
				return;
			d = $("#dlg").dialog({
				title : '修改新闻',
				width : 450,
				height : 200,
				href : '${ctx}/knowledge/update/' + row.id,
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						$("#mainform").submit();
					}
				}, {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});

		}
		//编辑新闻页面
		function editor() {
			var row = dg.datagrid('getSelected');
			if (rowIsNull(row))
				return;
			d = $("#dlg").dialog({
				title : '编辑新闻',
				top : 10,
				width : 980,
				height : 600,
				href : '${ctx}/knowledge/editor/' + row.id,
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						$("#editorform").submit();
					}
				}, {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});

		}
		//图片上传
		function uploadImg() {
			var row = dg.datagrid('getSelected');
			if (rowIsNull(row))
				return;
			d = $("#dlg").dialog({
				title : '图片上传',
				width : 450,
				height : 300,
				href : '${ctx}/knowledge/upload/' + row.id,
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						$("#uploadform").submit();
						setTimeout("dg.datagrid('reload')", 1500);
					}
				}, {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});

		}
		//新闻预览
		function detail(){
			var row = dg.datagrid('getSelected');
			if(rowIsNull(row)) return;
			
			var url = row.url;
			window.open(url,"","width=320,height=680,toolbar=no,scrollbars=yes,menubar=no,screenX=100,screenY=100");
		}
		//产品发布
		function publish(){
			var row = dg.datagrid('getSelected');
			if(rowIsNull(row)) return;
			if(row.publishStatus == '1') {
				parent.$.messager.alert('该文章已发布！');
				return;
			}
			parent.$.messager.confirm('提示', '确认要发布该文章么？', function(data){
				if (data){
					$.ajax({
						type:'get',
						url:"${ctx}/knowledge/publish/"+row.id,
						success: function(data){
							successTip(data,dg);
						}
					});
				} 
			});
		}
		//创建查询对象并查询
		function cx() {
			var obj = $("#searchFrom").serializeObject();
			obj.filter_LIKES_title = encodeURIComponent(obj.filter_LIKES_title);
			dg.datagrid('reload', obj);
		}
		var nowIcon;
		var icon_dlg;
	</script>
</body>

</html>